package com.elonnx.web;

import com.elonnx.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 学生列表的Servlet
 * @author 马元
 * @date 2024-07-12
 */
@WebServlet("/student/add")
public class StudentAddServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 接收参数
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        String gender = request.getParameter("gender");
        String birthday = request.getParameter("birthday");
        String money = request.getParameter("money");

        // 存库
        StudentService studentService = new StudentService();
        studentService.add(name, age, gender, birthday, money);

        // 跳转到列表页面
        response.sendRedirect(request.getContextPath() + "/student/list");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

}
